package jp.gr.java_conf.genzo.wifinotify;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.text.TextUtils;

public class AppSettings {

    public static final String KEY_NOTIFICATION = "PREF_KEY_NOTIFICATION";
    public static final String KEY_NOTIFICATION_RINGTONE = "PREF_KEY_NOTIFICATION_RINGTONE";
    public static final String KEY_NOTIFICATION_VIBRATOR = "PREF_KEY_NOTIFICATION_VIBRATOR";
    public static final String KEY_NOTIFICATION_LED = "PREF_KEY_NOTIFICATION_LED";
    public static final String KEY_NOTIFICATION_CANCEL = "PREF_KEY_NOTIFICATION_CANCEL";
    public static final String KEY_ADD_SSID = "PREF_KEY_ADD_SSID";
    public static final String KEY_TOAST = "PREF_KEY_TOAST";

    public static final String KEY_EXLUDE_SSID = "PREF_KEY_EXLUDE_SSID";

    private SharedPreferences mPref = null;
    private Editor mEditor = null;

    public AppSettings(Context context) {
        mPref = PreferenceManager.getDefaultSharedPreferences(context);
        mEditor = mPref.edit();
    }

    public boolean isNotification() {
        return mPref.getBoolean(KEY_NOTIFICATION, true);
    }

    public String getNotifyRingtone() {
        return mPref.getString(KEY_NOTIFICATION_RINGTONE, null);
    }

    public boolean isNotifyVibrator() {
        return mPref.getBoolean(KEY_NOTIFICATION_VIBRATOR, true);
    }

    public boolean isNotifyLED() {
        return mPref.getBoolean(KEY_NOTIFICATION_LED, true);
    }

    public boolean isToast() {
        return mPref.getBoolean(KEY_TOAST, false);
    }

    public String getExcludeSSIDRow() {
        return mPref.getString(KEY_EXLUDE_SSID, "");
    }

    static final String[] EMPTY = new String[0];

    public String[] getExcludeSSID() {
        String ssid = mPref.getString(KEY_EXLUDE_SSID, "");
        String[] result = EMPTY;
        if (!TextUtils.isEmpty(ssid)) {
            result = ssid.split(",");
        }
        return result;
    }

    public void setExcludeSSID(String value) {
        mEditor.putString(KEY_EXLUDE_SSID, value);
        mEditor.commit();
    }
}